package org.ceteca.explica.core.common;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.ceteca.explica.core.InterfaceExplica;
import org.ceteca.explica.core.partners.RappelTypeOT;

/**
 * Store class to hold the data of a price list.
 * <br/>
 * Responsibilities:
 * <li>
 * 	<ul> Store of flag data for exchanging data among presentation, 
 * business and data access layers. </ul>
 * </li>.
 * <br/>
 * @author Juan Díaz <juancarlosdiaz@ceteca.es>
 * Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <br/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <br/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */




public class PriceListOT extends BaseVO implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private long idPriceList;
	private Integer version= new Integer(0);
	private String description;
	private Date fromDate;
	private Date toDate;
	private Set<PriceListLineOT> lines;
	private boolean taxesInc;
	
	public PriceListOT() {
		idPriceList=0;
		description="";
		fromDate=new Date();
		toDate=new Date();
		lines=new HashSet<PriceListLineOT>();
		taxesInc=false;
		
	}

	@Override
	public boolean equals(Long id) {
		return getIdPriceList()==id.longValue();
	}

	@Override
	public String getEntityId() {
		return InterfaceExplica.EXPLICA_ENTITY_PRICELIST_ID;
	}

	@Override
	public long getInternalId() {
		return getIdPriceList();
	}

	@Override
	public String getInternalValue() {
		return getDescription();
	}

	public long getIdPriceList() {
		return idPriceList;
	}

	public void setIdPriceList(long idPriceList) {
		this.idPriceList = idPriceList;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getFromDate() {
		return fromDate;
	}

	public void setFromDate(Date fromDate) {
		this.fromDate = fromDate;
	}

	public Date getToDate() {
		return toDate;
	}

	public void setToDate(Date toDate) {
		this.toDate = toDate;
	}



	public Set<PriceListLineOT> getLines() {
		return lines;
	}

	public void setLines(Set<PriceListLineOT> lines) {
		this.lines = lines;
	}

	
	
	public boolean isTaxesInc() {
		return taxesInc;
	}

	
	public void setTaxesInc(boolean taxesInc) {
		this.taxesInc = taxesInc;
	}

	@Override
	public String toString() {
		StringBuffer result = new StringBuffer();
		try {
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
			result.append("\nID: ");
			result.append(getIdPriceList());
			result.append("\nDescription: ");
			result.append(getDescription());
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
			if (this.getLines()!=null)
			for (PriceListLineOT line:this.getLines()){
				if (line!=null)
					result.append(line.toString());
			}
		}
		catch (Exception ex) {
			System.out.println("Error formatting PriceListOT!");
			ex.printStackTrace();
			return null;
		}
		
		return result.toString();
	}

	
	
	
	   @Override
	    public int hashCode() {
	        final HashCodeBuilder hcb = new HashCodeBuilder();
	        hcb.append(getDescription());
	        hcb.append(getFromDate());
	        hcb.append(getToDate());
	        hcb.append(isTaxesInc());

	        return hcb.toHashCode();
	    }

	    
	    
	    @Override
	    public boolean equals(Object obj) {
	        boolean isEquals = false;
	        try {
	            final PriceListOT other = (PriceListOT)obj;
	            final EqualsBuilder eqb = new EqualsBuilder();
	            eqb.append(getDescription(), other.getDescription());
	            eqb.append(getFromDate(), other.getFromDate());
	            eqb.append(getToDate(), other.getToDate());
	            eqb.append(isTaxesInc(), other.isTaxesInc());
	            isEquals = eqb.isEquals();

	        } catch (Exception e) {
	            isEquals = false;
	        }

	        return isEquals;
	    }




	
}
